package com.fmsz.xmly.adapters.findrecom;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.activitys.findrecom.AlbumDetailActivity;
import com.fmsz.xmly.activitys.findrecom.SubjectDetailActivity;
import com.fmsz.xmly.entitys.findrecom.FindRecomSpecialEntity;
import com.fmsz.xmly.entitys.findrecom.SpecialChildEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/8.
 */

public class FindRecomSpecialAdapter extends RecyclerView.Adapter<FindRecomSpecialAdapter.ViewHolder> {
    private List<FindRecomSpecialEntity> list;
    private Context context;
    private LayoutInflater inflater;
    public FindRecomSpecialAdapter(List<FindRecomSpecialEntity> specialList, Context context) {
        this.list = specialList;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public FindRecomSpecialAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
        View view=inflater.inflate(R.layout.find_recom_special_item,parent,false);
        ViewHolder holder=new ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,SubjectDetailActivity.class);
                intent.putExtra("data",list.get(0).getList().get(viewType).getSpecialId());
                context.startActivity(intent);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(FindRecomSpecialAdapter.ViewHolder holder, int position) {
        SpecialChildEntity entity = list.get(0).getList().get(position);
        holder.title.setText(entity.getTitle());
        holder.subtitle.setText(entity.getSubtitle());
        holder.footnote.setText(entity.getFootnote());
        if (entity.getCoverPath()!=null){
            Picasso.with(context).load(entity.getCoverPath()).into(holder.image);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView image;
        TextView title,subtitle,footnote;
        public ViewHolder(View itemView) {
            super(itemView);
            image=(ImageView)itemView.findViewById(R.id.find_recom_special_item_iv);
            title=(TextView)itemView.findViewById(R.id.find_recom_special_item_title);
            subtitle=(TextView)itemView.findViewById(R.id.find_recom_special_item_subtitle);
            footnote=(TextView)itemView.findViewById(R.id.find_recom_special_item_footnote);
        }
    }
}
